package org.liveboardgames.agricola.control.delegates.action.processor
{
    import org.liveboardgames.agricola.control.delegates.helper.GameHelper;
    import org.liveboardgames.agricola.model.AgricolaModelLocator;
    import org.liveboardgames.agricola.model.PopupModel;
    import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.player.Player;
    
    import mx.collections.ListCollectionView;
    
    public class BakeActionProcessor extends ActionProcessor
    {
        public function BakeActionProcessor(action:Action)
        {
            super(action);
        }
        
        override public function execute():void
        {
            var player:Player = action.target as Player;
            
            // Need to offer the player the choice of the oven with which to bake (if 
            // they have several), and then the quantity of grain to bake
            var ovens:ListCollectionView = GameHelper.getOvens(player.farm);
            
            // Get the number of grains the player currently have
            var grains:int = player.farm.resources.getValue(ResourceTypeEnum.GRAIN);
            
            AgricolaModelLocator.getInstance().popups.numberOfAvailableGrains = grains;
            AgricolaModelLocator.getInstance().popups.ovens = ovens;
            
            AgricolaModelLocator.getInstance().popups.currentActionPopupIndex = PopupModel.POPUP_BAKE_INDEX;
        }
    }
}